package com.atguigu.gmall.product.config;


import io.minio.MinioClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件上传
 */
@Configuration
public class AppMinioAutoConfiguration {

    @Bean  //代表给容器中放一个组件，如果这个方法有参数，参数自动从容器中获取
    public MinioClient minioClient(AppMinioProperties minioProperties) throws Exception {
        MinioClient minioClient = new MinioClient(
                minioProperties.getEndpoint(),
                minioProperties.getAccessKey(),
                minioProperties.getAccessSecret());

        if(!minioClient.bucketExists(minioProperties.getBucket())){
            //桶不存在，则创建
            minioClient.makeBucket(minioProperties.getBucket());

            //设置为公共访问
            //  minioClient.setBucketPolicy(minioProperties.getBucket(),);
        }
        return minioClient;
    }
}
